home *** CD-ROM | disk | FTP | other *** search
- #include "Intuition_utils.h"
-
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #endif
-
-
- #define DONT_KNOW -2
-
- #define FIRST_V2_LIB 36
- #define FIRST_V2_1_LIB 38
- #define FIRST_V3_LIB 39
- #define FIRST_V3_1_LIB 40
-
- BOOL is_Workbench_v2( void )
- /* returns TRUE if you're running Workbench 2.0 */
- {
- static BOOL is_Wb2 = DONT_KNOW;
- struct Library *lib = NULL;
-
- if( DONT_KNOW == is_Wb2 )
- {
- lib = OpenLibrary( "intuition.library", FIRST_V2_LIB );
- if( lib != NULL )
- {
- is_Wb2 = TRUE;
- CloseLibrary( lib );
- }
- else
- is_Wb2 = FALSE;
- }
-
- return (BOOL) is_Wb2;
- }
-
-
- BOOL is_Workbench_v2_1( void )
- /* returns TRUE if you're running Workbench 2.0 */
- {
- static BOOL is_Wb2_1 = DONT_KNOW;
- struct Library *lib = NULL;
-
- if( DONT_KNOW == is_Wb2_1 )
- {
- lib = OpenLibrary( "intuition.library", FIRST_V2_1_LIB );
- if( lib != NULL )
- {
- is_Wb2_1 = TRUE;
- CloseLibrary( lib );
- }
- else
- is_Wb2_1 = FALSE;
- }
-
- return (BOOL) is_Wb2_1;
- }
-
- BOOL is_Workbench_v3( void )
- /* returns TRUE if you're running Workbench 2.0 */
- {
- static BOOL is_Wb3 = DONT_KNOW;
- struct Library *lib = NULL;
-
- if( DONT_KNOW == is_Wb3 )
- {
- lib = OpenLibrary( "intuition.library", FIRST_V3_LIB );
- if( lib != NULL )
- {
- is_Wb3 = TRUE;
- CloseLibrary( lib );
- }
- else
- is_Wb3 = FALSE;
- }
-
- return (BOOL) is_Wb3;
- }
-
- BOOL is_Workbench_v3_1( void )
- /* returns TRUE if you're running Workbench 2.0 */
- {
- static BOOL is_Wb3_1 = DONT_KNOW;
- struct Library *lib = NULL;
-
- if( DONT_KNOW == is_Wb3_1 )
- {
- lib = OpenLibrary( "intuition.library", FIRST_V3_1_LIB );
- if( lib != NULL )
- {
- is_Wb3_1 = TRUE;
- CloseLibrary( lib );
- }
- else
- is_Wb3_1 = FALSE;
- }
-
- return (BOOL) is_Wb3_1;
- }
-
-
- void GadgetRelativeCoords( struct Gadget *gadget,
- struct IntuiMessage *event,
- Point *point )
- {
- struct Window *window;
-
- window = event->IDCMPWindow;
-
- point->x = event->MouseX - gadget->LeftEdge;
- point->y = event->MouseY - gadget->TopEdge;
-
- if( window->Flags & GIMMEZEROZERO )
- {
- point->x -= window->BorderLeft;
- point->y -= window->BorderTop;
- }
-
- }
-
-
- #ifndef __GNUC__ /* no CHIP keyword */
- static USHORT __chip BusyPointerData[] =
- {
- 0x0000,0x0000,
- 0x0400,0x07C0,0x0000,0x07C0,0x0100,0x0380,0x0000,0x07E0,
- 0x07C0,0x1FF8,0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
- 0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,0x3FF8,0x7FFE,
- 0x3FF8,0x7FFE,0x1FF0,0x3FFC,0x07C0,0x1FF8,0x0000,0x07E0,
- 0x0000,0x0000,
- };
- #endif
-
- #ifndef __GNUC__ /* need to allocate the CHIPMEM manually for Busy pointer */
- void SetWaitPointer( struct Window *w )
- {
- if( is_Workbench_v3() ) /* use system busy pointer V39 and up */
- SetWindowPointer( w, WA_BusyPointer, TRUE );
- else
- SetPointer( w, BusyPointerData, 16, 16, -6, 0 );
- }
- #endif
- #ifdef __GNUC__
- USHORT *BusyPointerData = NULL; /* must be CHIP ram */
-
- static USHORT fastBusyPointerData[] =
- {
- 0x0000,0x0000,
- 0x0400,0x07C0,0x0000,0x07C0,0x0100,0x0380,0x0000,0x07E0,
- 0x07C0,0x1FF8,0x1FF0,0x3FEC,0x3FF8,0x7FDE,0x3FF8,0x7FBE,
- 0x7FFC,0xFF7F,0x7EFC,0xFFFF,0x7FFC,0xFFFF,0x3FF8,0x7FFE,
- 0x3FF8,0x7FFE,0x1FF0,0x3FFC,0x07C0,0x1FF8,0x0000,0x07E0,
- 0x0000,0x0000,
- };
-
- void SetWaitPointer( struct Window *w )
- {
- if( is_Workbench_v3() )
- SetWindowPointer( w, WA_BusyPointer, TRUE );
- else
- ; /* do nothing for now */
- /* should probably check an extern pointer for NULL
- * and if so allocate the chipmem to the pointer
- * but then we need to cleanup when done???
- */
-
- #if 0 /* not ready ready for primetime */
- {
- if( BusyPointerData == NULL ) /* first time called */
- {
- BusyPointerData = AllocMem( sizeof( fastBusyPointerData[], MEMF_CHIP|MEMF_CLEAR );
- CopyMem(BusyPointerData, fastBusyPointerData, (sizeof( fastBusyPointerData[] );
- }
- SetPointer( w, BusyPointerData, 16, 16, -6, 0 );
- }
- #endif /* not ready for prime time */
-
- }
- #endif /* __GNUC__ */
-
- struct IntuiMessage *WaitForMessage( struct MsgPort *mport )
- {
- struct IntuiMessage *imsg;
-
- for( ;; )
- {
- imsg = (struct IntuiMessage *)GetMsg( mport );
- if( imsg )
- return imsg;
- else /* EDB added else to make action more apparent */
- WaitPort( mport );
- }
- }
-
- struct Window *OpenWindowWithSharedUserPort( struct NewWindow *nw,
- struct MsgPort *shared )
- {
- ULONG IDCMPbuf;
- struct Window *w;
-
- IDCMPbuf = nw->IDCMPFlags;
- nw->IDCMPFlags = 0; /* no IDCMP flags. */
-
- if( w = SmartOpenWindow( nw ) )
- {
- w->UserPort = shared; /* assign UserPort. */
- ModifyIDCMP( w, IDCMPbuf ); /* turn on IDCMP */
- }
- nw->IDCMPFlags = IDCMPbuf; /* return 'nw' to its previous state. */
- return w;
- }
-
-
- void StripIntuiMessages( struct Window *w )
- /*
- *ASSUMES* a Forbid() has been called!
-
- Taken from 1.3 RKM:L&D, page 171
- */
- {
- struct MsgPort *mp;
- struct IntuiMessage *msg, *succ;
-
- mp = w->UserPort;
-
- /*
- * Loop through all messages waiting at this port, remove any
- * which are for Window 'w'.
- */
-
- msg = (struct IntuiMessage*) mp->mp_MsgList.lh_Head;
- while( succ = (struct IntuiMessage*) msg->ExecMessage.mn_Node.ln_Succ )
- {
- if( msg->IDCMPWindow == w )
- {
- Remove( (struct Node *) msg );
- ReplyMsg( (struct Message *) msg );
- }
-
- msg = succ;
- }
- }
-
- void CloseWindowWithSharedUserPort( struct Window *w )
- /* Taken from 1.3 RKM:L&D, page 171, 'CloseWindowSafely()' */
- {
- Forbid(); /* Turn off multitasking */
-
- StripIntuiMessages( w ); /* remove all messages for this window. */
-
- w->UserPort = NULL;
- ModifyIDCMP( w, 0 ); /* prevents new messages from occuring. */
- Permit();
-
- CloseWindow( w );
- }
-
-
- BOOL WindowSanityCheck( struct Screen *screen,
- Point *location,
- Point *size )
- /* returns FALSE if location or size was changed. */
- {
- BOOL ok = TRUE;
-
-
- if( size->x > screen->Width )
- {
- ok = FALSE;
- size->x = screen->Width;
- }
-
- if( size->y > screen->Height )
- {
- ok = FALSE;
- size->y = screen->Height;
- }
-
- /* size is now ok, so check location. */
- if( location->x + size->x >= screen->Width )
- {
- location->x = screen->Width - size->x;
- ok = FALSE;
- }
- if( location->y + size->y >= screen->Height )
- {
- location->y = screen->Height - size->y;
- ok = FALSE;
- }
-
- return ok;
- }
-
- #include <utility/tagitem.h>
-
- UWORD minimal_pens [1] = { (USHORT)~0 };
-
- /* EDB -- This should probably clone Workbench mode as a default */
- struct TagItem screen_tags_v2[] =
- {
- { SA_Pens, (ULONG) minimal_pens },
- { TAG_END, 0 }
- };
-
- struct TagItem screen_tags_v3[] =
- {
- { SA_Pens, (ULONG) minimal_pens },
- { SA_LikeWorkbench, TRUE },
- { TAG_END, 0 }
- };
-
- struct Screen *SmartOpenScreen( struct NewScreen *newscreen )
- {
- if( is_Workbench_v2() )
- {
-
- if( is_Workbench_v3() )
- return OpenScreenTagList( newscreen, screen_tags_v3 );
-
- else /* should try harder to clone workbench screen mode? */
- return OpenScreenTagList( newscreen, screen_tags_v2 );
- }
- else
- return OpenScreen( newscreen );
- }
-
- /* I'm not sure if there are other cases which require OpenWindowTags? -- EDB */
- struct TagItem window_tags[] =
- {
- { WA_NewLookMenus, TRUE }
- };
-
- struct Window *SmartOpenWindow( struct NewWindow *newwindow )
- {
- if( is_Workbench_v3() )
- {
- return OpenWindowTagList( newwindow, window_tags );
- }
- else
- return OpenWindow( newwindow );
- }
-
-
- void RemapImage( struct Image *image )
- {
- UWORD *plane1, *plane2, temp;
- short i, planesize;
-
- planesize = ( ( image->Width + 15 )/16 ) * image->Height;
-
- plane1 = &image->ImageData[0];
- plane2 = &image->ImageData[planesize];
- for( i = 0; i < planesize; i++ )
- {
- temp = plane1[i];
- plane1[i] = plane2[i];
- plane2[i] = temp;
- }
- }
-